package Service.Admin.Imp;

import Dao.DaoFactory;
import Dao.Process.StageTimeDao;
import Entity.MyTableData;
import Entity.Process.StageTime;
import Service.Admin.StageTimeService;
import Util.DBUtil;

import java.sql.Connection;
import java.util.List;

public class StageTimeServiceImp implements StageTimeService {
    private StageTimeDao stageTimeDao;
    private Connection conn;

    public StageTimeServiceImp(){
        conn = DBUtil.getConnByDruid();
        stageTimeDao = DaoFactory.getInstance("stageTimeDao");
    }

    @Override
    public MyTableData queryAllStageTime(){
        List<StageTime> stageTimes = stageTimeDao.queryAllStageTime(conn);
        DBUtil.closeConn(conn);
        return new MyTableData(0,"",stageTimes.size(),stageTimes);
    }

    @Override
    public Boolean updateStageTime(String startTime, String endTime, String stageId){
        boolean flag = stageTimeDao.updateStageTime(startTime,endTime,stageId,conn) == 1;
        DBUtil.closeConn(conn);
        return flag;
    }

    @Override
    public MyTableData getStageTimeBystage(String stageId){
        List<StageTime> stageTimes = stageTimeDao.getStageTimeBystage(stageId,conn);
        DBUtil.closeConn(conn);
        return new MyTableData(0,"",stageTimes.size(),stageTimes);
    }

}
